#include "stdafx.h"
#include "BoxComponent.h"

BoxComponent::BoxComponent( Ogre::Vector3 position, Ogre::Vector3 dimensions, float mass = 1, bool movable = true ) {
	hkVector4 dim = hkVector4( dimensions.x, dimensions.y, dimensions.z );
	hkVector4 pos = hkVector4( position.x, position.y, position.z );

	// Create box shape using given dimensions
	hkReal m_fhkConvexShapeRadius = 0.05f;
	hkpShape* movingBodyShape = new hkpBoxShape( dim, m_fhkConvexShapeRadius );

	// Compute the inertia tensor from the shape
	hkpMassProperties m_massProperties;
	
	hkpInertiaTensorComputer::computeShapeVolumeMassProperties( movingBodyShape, mass, m_massProperties );

	// Create rigid body information structure 
	hkpRigidBodyCinfo m_rigidBodyInfo;
	
	// Assign the rigid body properties
	m_rigidBodyInfo.m_position = pos;
	m_rigidBodyInfo.m_mass = m_massProperties.m_mass;
	m_rigidBodyInfo.m_centerOfMass = m_massProperties.m_centerOfMass;
	m_rigidBodyInfo.m_inertiaTensor = m_massProperties.m_inertiaTensor;
	m_rigidBodyInfo.m_shape = movingBodyShape;
	
	// If box is fixed or able to move
	if(movable) {
		m_rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
	} else {
		m_rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
	}
	
	// Create new rigid body with supplied info
	m_rigidBody = new hkpRigidBody(m_rigidBodyInfo);
	movingBodyShape->removeReference();
}